package cn.com.b2office.struts2.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import cn.com.b2office.domain.District;
import cn.com.b2office.domain.MemberAddress;
import cn.com.b2office.domain.User;
import cn.com.b2office.service.AddressService;
import cn.com.b2office.service.MemberService;

import com.opensymphony.xwork2.ActionSupport;

public class AddAddressAction extends ActionSupport implements SessionAware {

	private static final long serialVersionUID = 2555421778949385675L;

	private Map session = null;

	private List<District> districtList = null;

	private AddressService addressService = null;

	private MemberService memberService = null;

	private String cname = null;

	private String tel = null;

	private String mobile = null;

	private int countyid = 0;

	private String addr = null;

	public void setSession(Map session) {
		this.session = session;
	}

	public void validate() {
		// TODO:进行数据验证
	}

	public String execute() throws Exception {
		User user = (User) session.get("user");
		if (user == null)
			return "login";

		MemberAddress address = new MemberAddress();
		address.setMemberid(user.getMemberId());
		address.setAddr(addr);
		address.setCountyid(countyid);
		address.setMobil(mobile);
		address.setTel(tel);
		address.setCname(cname);
		memberService.createAddress(address);
		return SUCCESS;
	}

	public String showPage() throws Exception {
		districtList = addressService.listDistricts();
		return SUCCESS;
	}

	public void setAddressService(AddressService addressService) {
		this.addressService = addressService;
	}

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}

	public List<District> getDistrictList() {
		return districtList;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

	public void setCountyid(int countyid) {
		this.countyid = countyid;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

}
